from math import inf
from typing import *


class Solution:

    def maxProfit(self, prices: List[int]) -> int:
        mn = inf
        ans = 0
        for v in prices:
            ans = max(ans, v - mn)
            mn = min(v, mn)
        return ans
